#include "Tools.h"
#include <osgEarth/Config>
#include <fstream>
#include "AddMask.h"
#include "Services/ToolsGenCenter.h"
#include <QMessageBox>

int Tools::handle(std::string xml)
{
	osgEarth::Config doc;
	//std::ifstream in("../user_data/hbt/config/sys.xml");
	std::ifstream in(xml);
	if (!in.good()) return -1;

	if (!doc.fromXML(in)) {
		return -2;
	}
	const osgEarth::Config* cfg = doc.child_ptr("tool");
	if (!cfg) return -3;

	auto* cmdnode = cfg->child_ptr("cmd");
	if (!cmdnode)  return -4;
	
	std::string cmd = "";

	cmd = cmdnode->value();


	if (cmd == "ADD_MASK") {
		AddMask addmask;
		addmask.handle(cfg);
	}
	if (cmd == "ToolsGenCenter") {
		ToolsGenCenter tgc;
		tgc.handle(cfg);
	}
	QMessageBox::information(0, "", "DONE!");
	return 0;
}
